package de.baumann.browser.fragments

import android.content.Intent
import android.os.Handler
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import de.baumann.browser.R
import de.baumann.browser.activitys.H5Activity
import de.baumann.browser.adapter.StealAdapter
import de.baumann.browser.api.net.vo.Steal
import de.baumann.browser.base.BaseOdinFragment
import de.baumann.browser.iview.IStealView
import de.baumann.browser.present.StealPresenter
import de.baumann.browser.utils.Constants
import kotlinx.android.synthetic.main.fragment_steal.*

/**
 *@author:
 *@date:2019/1/25 16:28
 *@discription : 可收取 / 常来收取 列表
 */
@Deprecated("5.0.0版本删除")
class StealFragment : BaseOdinFragment<IStealView, StealPresenter>(), IStealView {

    private lateinit var stealAdapter: StealAdapter

    override fun getLayout(): Int {
        return R.layout.fragment_steal
    }

    override fun initView(view: View) {
        rvSteal.layoutManager = LinearLayoutManager(context)
        stealAdapter = StealAdapter(R.layout.recycler_item_steal)
        rvSteal.adapter = stealAdapter
        stealAdapter.setOnItemClickListener { adapter, _, position ->
            run {
                val steal = adapter.getItem(position) as Steal
                if (steal.canState == 1) {
                    val intent = Intent(context, H5Activity::class.java)
                    intent.putExtra("isUseTitle", true)
                    intent.putExtra("flag", 3)
                    intent.putExtra("title", "采矿")
                    intent.putExtra("stolenId", steal.userId)
                    intent.putExtra("url", Constants.STEAL_GAME_URL)
                    startActivity(intent)
                }
            }
        }
    }

    override fun initData() {
    }

    override fun createPresenter(): StealPresenter {
        return StealPresenter()
    }

    override fun createView(): IStealView {
        return this
    }

    override fun onResume() {
        super.onResume()
        if (getIsSteal()) {
            Handler().postDelayed({
                getPresenter().getCanStealList()
            },1000)
        } else {
            Handler().postDelayed({
                getPresenter().getOftenStealList()
            },2000)
        }
    }

    override fun getIsSteal(): Boolean {
        return arguments!!.getBoolean("steal", false)
    }

    override fun setStealData(data: List<Steal>?) {
        stealAdapter.setNewData(data)
    }

}
